<?php
class TicketController extends Controller
{
    private $_salt = "1da4j6";
    private $_username = "aishua";
    private $_password = "aishuabj";
    public function actionBuyByUsername()
    {
        if(!isset($_POST["username"])||!isset($_POST["password"])
                ||!isset($_POST["timestamp"])||!isset($_POST["md5"])
                ||!isset($_POST["telephone"])||!isset($_POST["packageid"]))
        {
            JSONHelper::echoJSON(false,"非法请求");
        }
        date_default_timezone_set('Asia/Shanghai'); 
        if(abs($_POST["timestamp"] - time())>7200){
            JSONHelper::echoJSON(false,"非法时间戳");
        }
        if($_POST["username"]!=$this->_username){
            JSONHelper::echoJSON(false,"非法用户");
        }
        if($_POST["password"]!=$this->_password){
            JSONHelper::echoJSON(false,"密码错误");
        }
        
        if(md5(md5($_POST["username"].$_POST["password"].$this->_salt.$_POST["timestamp"]))!=$_POST["md5"]){
            JSONHelper::echoJSON(false,"校验失败");
        }
        JSONHelper::echoJSON(true,array("ticketid"=>"3212343"));
    }
    public function actionTest()
    {
        $this->renderPartial("test");
    }
}
